import 'package:bloc_usage/global/CountBloc.dart';
import 'package:flutter/material.dart';

class SecondPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => SecondState();
}

class SecondState extends State<SecondPage> {
  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: countBloc.stream,
      initialData: countBloc.value,
      builder: (context, snapshot) {
        return Scaffold(
          appBar: AppBar(
            title: Text("SecondPage use the bloc"),
            centerTitle: true,
          ),
          body: SizedBox.expand(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Text("you tap ${snapshot.data}"),
              GestureDetector(
                child: Text(
                  "Back ~",
                  textScaleFactor: 3,
                ),
                onTap: () => Navigator.of(context).pop(),
              )
            ],
          )),
          floatingActionButton: FloatingActionButton(
            onPressed: () {
              countBloc.increment();
            },
            child: Icon(Icons.add),
          ),
        );
      },
    );
  }
}
